package com.djinfo.work.service.impl;

import com.djinfo.work.common.service.impl.BaseServiceImpl;
import com.djinfo.work.dao.impl.NoticeDaoImpl;
import com.djinfo.work.entity.SysMessageEntity;
import com.djinfo.work.entity.SysMessageUserEntity;
import com.djinfo.work.service.MessagesUsersService;
import org.springframework.stereotype.Service;


/**
 *
 */
@Service("MessagesUsersService")
public class MessagesUsersServiceImpl extends BaseServiceImpl<SysMessageUserEntity,NoticeDaoImpl> implements MessagesUsersService {

	/**
	 * 消息通知对象的删除
	 * @param id
     */
	@Override
	public void delSomeData(String id) {
		try {
			String hql = "delete from SysMessageUserEntity where messagesUserid='"+id+"'";
			this.delSome(hql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 更新消息通知对象
	 * @param sysMessageEntity
	 * @param nowTime
     * @param id
     */
	@Override
	public void updateMess(SysMessageEntity sysMessageEntity, String nowTime, String id) {
		try {
			String[] receives = sysMessageEntity.getReceiveObject().split(",");
			for(String r:receives){
                SysMessageUserEntity sysMessageUserEntity =new SysMessageUserEntity();
                sysMessageUserEntity.setMessagesUserid(sysMessageEntity.getId());
                sysMessageUserEntity.setUserName(r);
                sysMessageUserEntity.setCreateTime(nowTime);
                sysMessageUserEntity.setUpdateTime(nowTime);
                sysMessageUserEntity.setCreateUser(id);
                sysMessageUserEntity.setUpdateUser(id);
                this.save(sysMessageUserEntity);
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 新增消息的通知对象
	 * @param sysMessageEntity
	 * @param nowTime
     * @param id
     */
	@Override
	public void saveMess(SysMessageEntity sysMessageEntity, String nowTime, String id) {
		try {
			String[] receives = sysMessageEntity.getReceiveObject().split(",");
			for(int i=0;i<receives.length;i++){
                SysMessageUserEntity sysMessageUserEntity =new SysMessageUserEntity();
                sysMessageUserEntity.setMessagesUserid(sysMessageEntity.getId());
                sysMessageUserEntity.setUserName(receives[i]);
                sysMessageUserEntity.setCreateTime(nowTime);
                sysMessageUserEntity.setUpdateTime(nowTime);
                sysMessageUserEntity.setCreateUser(id);
                sysMessageUserEntity.setUpdateUser(id);
                this.save(sysMessageUserEntity);
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
